(function ($) {
	var loginInfo
	var Limit = 20,Start=0,sourceData,IsCount = '',totalScore = 0,quesData=[],saveCount=0,RowId=""
	var disabledStr = ''
	var timePicker;
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!$.os.plus) {
		baseSetup()
	}
	
	function saveDetailData(){
		blurAllInput()
		var isAllMastAns = true
		mui('#UL li.mui-table-view-cell').each(function (index,element) {
			var oneDict = quesData[index];
			if (oneDict['IsRequired'] != 'true') { //非必填
				return true
			}
			var classStr = element.getAttribute('class')
			if (classStr.indexOf('jumped') != -1) { //被跳过的题目
				return true
			}
			var ansDict = getAnswer(element);
			if (ansDict['isEmpty']) {
				isAllMastAns = false;
			}
		});
		if (!isAllMastAns) {
			mui.toast('有必填项未填写哦')
			return
		}
		var status = this.getAttribute('data-id')
		var tip = '正在保存'
		if (status == 'Y') {
			var tip = '正在提交'
		}
		var rw = sourceData['RowId']
		plus.nativeUI.showWaiting(tip,{modal:false})
		saveCount = 0
		saveMainForm(status,rw)
	}
	
	function saveMainForm(status,rw){
		//WardDR|病区id^SurveyPerson|填写人人员id^SurveyDR|调查内容id^ReleaseDR|调查任务id^IsCount|是否计分^TotalScore|得分^RowId|^Explain|问卷说明
		//^Creater|创建人人员id^Type|N(N护士)^Status|N(N保存、Y提交)
		var parr = 'WardDR|'+sourceData['WardDR']+'^SurveyPerson|'+sourceData['SurveyPerson']+'^SurveyDR|'+sourceData['SurveyDR']+
			'^ReleaseDR|'+sourceData['ReleaseDR']+'^IsCount|'+IsCount+'^TotalScore|'+keepTwoDecimalPlaces(totalScore)+'^RowId|'+rw+
			'^Explain|'+sourceData['Explain']+'^Creater|'+loginInfo['loginID']+'^Type|N^Status|'+status;
		//console.log(parr)
		var pdict = {'parr':parr}
		var paramDict = {'method':'web.INMSurveyComm:SaveSurveyForm','params':JSON.stringify(pdict),'type':'Method'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var rw = parseInt(result['msg'])
			if (isNaN(rw)) {
				plus.nativeUI.closeWaiting()
				mui.toast(result['msg'])
				return;
			}
			sourceData['Status'] = status
			sourceData['RowId'] = rw
			mui('#UL li.mui-table-view-cell').each(function (index,element) {
				saveDetailOneData(element,rw,index)
			});
		}, function(errorStr) {
			plus.nativeUI.closeWaiting()
		});
	}
	
	function saveDetailOneData(liDom,rw,index){
		var ansStr=''
		var classStr = liDom.getAttribute('class')
		var isJumped = classStr.indexOf('jumped')!= -1
		if (isJumped) {
			ansStr ='Answer|^AnswerInput|'
		}else{
			ansStr = getAnswer(liDom).ans
		}
		var oneDict = quesData[index];
		if (RowId == "") {//首次提交
			////IconClasses|el-icon-star-on,el-icon-star-on,el-icon-star-on^Texts|1,2,3,4,5^
			for (let key in oneDict) {
				if (key == 'Answer' || key == 'Rules') {
					continue
				}
				if ('RowId' == key) {
					ansStr += '^QuesDR|'+oneDict[key]
					continue
				}
				if (key == 'ShowFlag') {
					if (isJumped) {
						ansStr += '^'+key +'|N'
					}else{
						ansStr += '^'+key +'|Y'
					}
					continue
				}
				ansStr += '^'+key +'|'+oneDict[key]
			}
			ansStr += '^'
			if (classStr.indexOf('gauge')!= -1) { //量表
				var typeStr = ''
				var textStr = ''
				//选项 描述」分数」是否填空」是否默认」id
				var ArrangeType = oneDict['ArrangeType']
				var QuesOption = oneDict['QuesOption'].split('「')
				for (var i = 0; i < QuesOption.length;i++) {
					var oneOp = QuesOption[i].split('」')
					if (i != 0) {
						if (i < 3) {
							
						}
						typeStr += ','
						textStr += ','
					}
					if (i < 3) {
						typeStr +=oneDict['ArrangeType']
					}
					textStr += oneOp[0]
				}
				ansStr += 'IconClasses|'+typeStr+'^Texts|'+textStr+'^'
			}
		}else{
			var quesRw = 'rw|'+oneDict['rw']+'^'
			if (isJumped) {
				ansStr = quesRw+ansStr+ '^ShowFlag|N'
			}else{
				ansStr = quesRw+ansStr + '^ShowFlag|Y'
			}
		}
		
		//rw|子表id^Answer|答案^AnswerInput|答案(可以填空时输入的结果)
		var pdict = {'parr':ansStr,'par':rw}
		//console.log(JSON.stringify(pdict));
		//return
		var paramDict = {'method':'web.INMSurveyComm:SaveSurveyFormSub','params':JSON.stringify(pdict),'type':'Method'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(pdict)+" "+JSON.stringify(result))
			saveCount += 1
			if (saveCount == quesData.length) {
				plus.nativeUI.closeWaiting()
				mui.back()
			}
		}, function(errorStr) {
			saveCount += 1
			if (saveCount == quesData.length) {
				plus.nativeUI.closeWaiting()
				mui.back()
			}
		});
	}
	
	function getStatDetailData(){
		//parr 未填写的入参（SurveyDR^Y） 已保存或者已提交（RowId）
		//input	检索信息 start	首条数据索引 limit	列表行数 role	角色id APPLoginID	用户id nurseid	人员id
		var method = 'web.INMDBComm:FindSurveyFormSub'
		var parr = sourceData['SurveyDR']+'^Y'
		if (sourceData['RowId'] != '') {
			parr = sourceData['RowId']
			method='web.INMSurveyComm:FindSurveyFormSub';
		}
		var pdict = {'parr':parr,'input':'','start':0,'limit':Limit,'role':loginInfo['loginRoleCodes'],'APPLoginID':loginInfo['loginID'],'nurseid':loginInfo['loginID']}
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'RecQuery'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataArr = result.data
			quesData = dataArr
			updateStatUI(dataArr)
			if (sourceData['Status'] != 'Y') {
				$('.submitBtn')[0].style.display = 'block'
				$('.saveBtn')[0].style.display = 'block'
			}
		}, function(errorStr) {
			
		});
	}
	
	function updateStatUI(dataArr,type){
		var UL=$('#UL')[0];
		if (Start == 0) {
			UL.innerHTML = ''
		}
		
		var oldCount = UL.querySelectorAll('li').length;
		for (var i = 0; i < dataArr.length;i++) {
			var oneData = dataArr[i];
			var isRequired = oneData['IsRequired']
			var quesType = oneData['QuesType']
			var quesDesc = oneData['QuesDesc']
			var writeTips = oneData['WriteTips']
			var ShowFlag = oneData['ShowFlag'] //N 不显示 Y显示
			var JumpType = oneData['JumpType'] //N:无条件跳题 X:选项跳题 G:题目关联
			var RelatedSort = oneData['RelatedSort'] //跳转到的题目序号
			var newLi = document.createElement('li')
			newLi.setAttribute('class','mui-table-view-cell')
			newLi.setAttribute('data-type',quesType)
			newLi.setAttribute('sort',oneData['Sort'])
			
			if (ShowFlag == 'N') {
				newLi.classList.add('jumped')
			}
			var html = '<div class="queTitle">'
			if (isRequired == 'true') {  // 必答
				html += '<div class="mustBe">*</div>';
			}
			html +=oneData['Sort'] + '、'+ quesDesc;
			if (writeTips != "") {
				html += '<div class="nurfont nur-wenhao tip" data-title="'+writeTips+'"></div>' 
			}
			if (isRequired == 'true') {  // 必答
				var Rules = oneData['Rules'].split('」') // "true」不能为空",
				html += '<div class="emptyTip">'+Rules[1]+'</div>';
			}
			html += '</div>'
			var typeClass = ''
			switch (quesType){
				case "单选":
					typeClass = 'radio'
					html +=createRadioCell(oneData,i);
					break;
				case "多选":
					typeClass = 'checkBox'
					html +=createCheckboxCell(oneData,i);
					break;
				case "单项填空":
					typeClass = 'SingleBlank'
					html +=createSingleBlankCell(oneData,i);
					break;
				case "多项填空":
					typeClass = 'multiBlank'
					html +=createMultiBlankCell(oneData,i);
					break;
				case "量表":
					typeClass = 'gauge'
					html +=createGaugeCell(oneData,i);
					break;
				case "滑动":
					typeClass = 'slide'
					html +=createSlideCell(oneData,i);
					break;
				case "日期":
					typeClass = 'date'
					html +=createDateCell(oneData,i);
					break;
				case "时间":
					typeClass = 'time'
					html +=createTimeCell(oneData,i);
					break;
				default:
					continue;
					break;
			}
			if (JumpType == 'N' || JumpType == 'X') {
				newLi.setAttribute('hasjump','1')
				if (JumpType == 'N') {
					newLi.setAttribute('anyjump',RelatedSort)
				}
			}else if(JumpType == 'G'){ //G:题目关联
				newLi.setAttribute('relation',RelatedSort+';'+oneData['RelatedSub']) //关联谁
				var relateLi = UL.querySelector('li[sort="'+RelatedSort+'"]')
				if (relateLi) {
					var oldrelated = relateLi.getAttribute('related')
					if (!oldrelated) {
						oldrelated=''
					}else{
						oldrelated=oldrelated+'^'
					}
					relateLi.setAttribute('related',oldrelated+oneData['Sort']+';'+oneData['RelatedSub']) //被关联
				}
			}
			newLi.classList.add(typeClass)
			newLi.id = (i+oldCount)+'-li';
			newLi.innerHTML = html;
			if (quesType == '单项填空') {
				newLi.querySelector('textarea').value = oneData['Answer']
			}
			UL.appendChild(newLi);
		}
		$('#totalScore')[0].innerHTML = keepTwoDecimalPlaces(totalScore)
	}
	
	//单选
	function createRadioCell(oneData,index){
		//console.log(JSON.stringify(oneData));
		//「分割 选项描述」分数」是否填空」是否默认」id
		var answer = oneData['Answer']
		var answerInput = oneData['AnswerInput'] == undefined?"":oneData['AnswerInput']; //"」啊啊啊啊"
		var QuesOption = oneData['QuesOption'].split('「')
		var inputArr = answerInput.split('」')
		var RelatedSort = oneData['RelatedSort'] //跳转到的题目序号
		var RelatedSub = ','+oneData['RelatedSub']+',' //'0,1,2,3,4'

		var html = ''
		for (var i = 0; i < QuesOption.length;i++) {
			var oneOp = QuesOption[i].split('」')
			var active = '',disabled = 'disabled',value=""
			if (answer == ''&&oneOp[3] == 'true') {
				active = 'dhc-active'
				disabled = ''
				value=inputArr[i]==undefined?"":inputArr[i]
				totalScore += parseFloat(oneOp[1])
			}else if (answer == oneOp[4]) { //是答案
				disabled = ''
				active = 'dhc-active'
				value=inputArr[i]==undefined?"":inputArr[i]
				totalScore += parseFloat(oneOp[1])
			}
			html += '<div class="option '+active+'" data-score="'+oneOp[1]+'" data-id="'+oneOp[4]+'">'+
				'<div class="circle"></div><div class="opTitle">'+oneOp[0]+'</div>'
			if (oneOp[2] == 'true') {
				html +='<input type="text" '+disabled+' class="mui-input-clear" value="'+value+'">'
			}
			html += '</div>';
		}
		return html
	}
	function getRadioAns(liDom){
		var options = liDom.querySelectorAll('.option')
		var isEmpty = true
		var AnswerInput = '',valueStr = ''
		for (var i = 0; i < options.length;i++) {
			var option = options[i]
			if (i != 0) {
				AnswerInput += '」'
			}
			if (option.getAttribute('class').indexOf('dhc-active') == -1) {
				continue
			}
			isEmpty = false
			valueStr = option.getAttribute('data-id')
			var input = option.querySelector('input')
			if (input) {
				AnswerInput += input.value
			}
		}
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && isEmpty) {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+valueStr+'^AnswerInput|'+AnswerInput,'isEmpty':isEmpty};
	}
	//多选
	function createCheckboxCell(oneData,index){
		
		//选项 描述」分数」是否填空」是否默认」id
		var QuesOption = oneData['QuesOption'].split('「')
		var answer = '「'+oneData['Answer']+'「'
		var answerInput = oneData['AnswerInput'] == undefined?"":oneData['AnswerInput'];
		var inputArr = answerInput.split('」')
		var RelatedSort = oneData['RelatedSort'] //跳转到的题目序号
		var RelatedSub = ','+oneData['RelatedSub']+',' //'0,1,2,3,4'
		var html = ''
		
		for (var i = 0; i < QuesOption.length;i++) {
			var oneOp = QuesOption[i].split('」')
			var active = '',disabled = 'disabled',value=""
			
			if (answer == '「「'&&oneOp[3] == 'true') {
				active = 'dhc-active'
				disabled = ''
				value=inputArr[i]==undefined?"":inputArr[i]
				totalScore += parseFloat(oneOp[1])
			}else if (answer != "「「" && answer.indexOf('「'+oneOp[4]+'「')!= -1) { //是答案
				disabled = ''
				active = 'dhc-active'
				value=inputArr[i]==undefined?"":inputArr[i]
				totalScore += parseFloat(oneOp[1])
			}
			html += '<div class="option '+active+'" data-score="'+oneOp[1]+'" data-id="'+oneOp[4]+'">'+
				'<div class="nurfont square"></div><div class="opTitle">'+oneOp[0]+'</div>'
			if (oneOp[2] == 'true') {
				html +='<input type="text" '+disabled+' class="mui-input-clear" value="'+value+'">'
			}
			html += '</div>';
		}
		return html;
	}
	function getCheckboxAns(liDom){
		var options = liDom.querySelectorAll('.option')
		var AnswerInput = '',valueStr = ''
		var isEmpty = true
		for (var i = 0; i < options.length;i++) {
			var option = options[i]
			if (i != 0) {
				AnswerInput += '」'
			}
			if (option.getAttribute('class').indexOf('dhc-active') == -1) {
				continue
			}
			isEmpty = false
			if (valueStr != '') {
				valueStr += '「'
			}
			valueStr += option.getAttribute('data-id')
			var input = option.querySelector('input')
			if (input) {
				AnswerInput += input.value
			}
		}
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && isEmpty) {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+valueStr+'^AnswerInput|'+AnswerInput,'isEmpty':isEmpty};  //Answer|1「2^AnswerInput|」」噢噢噢噢
	}
	//单项填空
	function createSingleBlankCell(oneData,index){
		//console.log(JSON.stringify(oneData))
		var answer = oneData['Answer']
		var placeholder = ''
		if (disabledStr == '') {
			placeholder = '请填写'
		}
		return '<textarea '+disabledStr+' value="'+answer+'" placeholder="'+placeholder+'"></textarea>'
	}
	function getSingleBlankAns(liDom){
		var valueStr = liDom.querySelector('textarea').value
		var isEmpty = true
		if (valueStr != '') {
			isEmpty = false
		}
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && isEmpty) {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+valueStr+'^AnswerInput|','isEmpty':isEmpty};
	}
	//多项填空
	function createMultiBlankCell(oneData,index){
		//console.log(JSON.stringify(oneData))
		var answer = oneData['Answer'];//Answer": "多项输入1「多项输入12「多项输入123",
		var QuesDesc = oneData['QuesDesc']
		var underCount = QuesDesc.split('_')
		var count = 0
		var start = 0
		mui.each(underCount,function (index,element) {
			if (element == '') {
				if (start == 0) {
					count +=1
				}
				start += 1
				return true
			}
			if (start == 0) {
				return true
			}
			start = 0;
		});
		var answerArr = answer.split('「')
		var html = ''
		for (var i = 0; i < count;i++) {
			var value = answerArr[i]==undefined?"":answerArr[i]
			html +='<input type="text" '+disabledStr+' class="mui-input-clear" value="'+value+'">'
		}
		return html
	}
	function getMultiBlankAns(liDom){
		var doms = liDom.querySelectorAll('input')
		var valueStr = '' //多项输入1「多项输入12「多项输入123
		var isEmpty = true
		for (var i = 0; i < doms.length;i++) {
			if (i > 0) {
				valueStr += '「'
			}
			if (doms[i].value != '') {
				isEmpty = false
			}
			valueStr += doms[i].value
		}
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && isEmpty) {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+valueStr+'^AnswerInput|','isEmpty':isEmpty};
	}
	//量表 样式:星星/月亮/太阳/云朵
	function createGaugeCell(oneData,index){
		//console.log(JSON.stringify(oneData))
		//选项 描述」分数」是否填空」是否默认」id
		var html = '<div class="option">'
		var ArrangeType = oneData['ArrangeType']
		var QuesOption = oneData['QuesOption'].split('「')
		var answer = oneData['Answer'];
		if (answer != '') {
			totalScore += parseInt(answer)
		}
		for (var i = 0; i < QuesOption.length;i++) {
			var oneOp = QuesOption[i].split('」')
			var active = ''
			if (answer != ''&& oneOp[1] <= answer) {
				active = 'dhc-active'
			}
			html += '<div class="nurfont nur-'+ArrangeType+' '+active+'" data-score="'+oneOp[1]+'" data-index="'+oneOp[4]+'"></div>'
		}
		html += '</div>';
		return html
	}
	function getGaugeAns(liDom){
		var doms = liDom.querySelectorAll('.nurfont.dhc-active')
		var valueStr = ''
		if (doms.length > 0) {
			valueStr = doms[doms.length - 1].getAttribute('data-score');
		}
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && valueStr == "") {
			emptyTip.classList.add('emptyStyle');
		}
		return {'ans':'Answer|'+valueStr+'^AnswerInput|','isEmpty':(valueStr == '')};
	}
	//滑动 --最大值/最小值  最大值文字/最小值 文字
	function createSlideCell(oneData,index){
		//console.log(JSON.stringify(oneData))
		var minValue = parseFloat(oneData['QuesMin'])
		var maxValue = parseFloat(oneData['QuesMax']) - minValue
		var answer = oneData['Answer']
		answer = answer==""?minValue:parseFloat(answer) - minValue;
		var tip = answer
		var left = '0px'
		var percent = 100*answer/(maxValue - minValue)
		if (percent < 5) {
			left = '0'
		}else{
			left = 'calc('+percent+'% - 15px)'
		}
		var html ='<div class="mui-input-row mui-input-range">'+
			'<input type="range" '+disabledStr+' value="'+answer+'" min="'+minValue+'" max="'+maxValue+'" >'+
			'<span class="mui-tooltip" style="left:'+left+'">'+tip+'</span></div>'+
			'<div class="option"><div class="minValue">'+oneData['QuesMinDesc']+'</div><div class="maxValue">'+oneData['QuesMaxDesc']+'</div></div>';
		return html
	}
	function getSlideAns(liDom){
		var valueStr = liDom.querySelector('input[type="range"]').value
		return {'ans':'Answer|'+valueStr+'^AnswerInput|','isEmpty':false};
	}
	//日期
	function createDateCell(oneData,index){
		var answer = oneData['Answer'];
		return '<div class="nurfont nur-rili">'+answer+'</div>'
	}
	function getDateAns(liDom){
		var dateStr = liDom.querySelector('.nur-rili').innerText
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && dateStr == "") {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+dateStr+'^AnswerInput|','isEmpty':(dateStr=="")};
	}
	//时间
	function createTimeCell(oneData,index){
		var answer = oneData['Answer'];
		return '<div class="nurfont nur-shijian">'+answer+'</div>'
	}
	function getTimeAns(liDom){
		var timeStr = liDom.querySelector('.nur-shijian').innerText
		var emptyTip = liDom.querySelector('.emptyTip')
		if (emptyTip && timeStr == "") {
			emptyTip.classList.add('emptyStyle')
		}
		return {'ans':'Answer|'+timeStr+'^AnswerInput|','isEmpty':(timeStr=="")};
	}
	
	function getAnswer(liDom){
		//console.log(liDom.outerHTML);
		var quesType = liDom.getAttribute('data-type')
		var naswerDict = ''
		switch (quesType){
			case "单选":
				naswerDict = getRadioAns(liDom)
				break;
			case "多选":
				naswerDict = getCheckboxAns(liDom);
				break;
			case "单项填空":
				naswerDict = getSingleBlankAns(liDom)
				break;
			case "多项填空":
				naswerDict = getMultiBlankAns(liDom)
				break;
			case "量表":
				naswerDict = getGaugeAns(liDom)
				break;
			case "滑动":
				naswerDict = getSlideAns(liDom)
				break;
			case "日期":
				naswerDict = getDateAns(liDom)
				break;
			case "时间":
				naswerDict = getTimeAns(liDom)
				break;
		}
		return naswerDict
	}
	
	function tipShow(){
		var titleStr = this.getAttribute('data-title')
		$('#tipContent')[0].innerHTML = titleStr
		$('#tipPopo').popover('toggle');
	}
	function radioTapped(){
		blurAllInput()
		var parentNode = this.parentNode
		var emptyStyleDom = parentNode.parentNode.querySelector('.emptyStyle')
		if (emptyStyleDom) {
			emptyStyleDom.classList.remove('emptyStyle')
		}
		if (parentNode.getAttribute('class').indexOf('dhc-active') != -1) {
			return;
		}
		var oldActive = parentNode.parentNode.querySelector('.dhc-active')
		if (oldActive) {
			totalScore -= parseFloat(oldActive.getAttribute('data-score'))
			oldActive.classList.remove('dhc-active')
			var inputDom = oldActive.querySelector('input')
			if (inputDom) {
				inputDom.setAttribute('disabled','')
			}
		}
		totalScore += parseFloat(parentNode.getAttribute('data-score'))
		parentNode.classList.add('dhc-active')
		var inputDom = parentNode.querySelector('input')
		if (inputDom) {
			inputDom.removeAttribute('disabled')
		}
		$('#totalScore')[0].innerHTML = keepTwoDecimalPlaces(totalScore)
		var liDom = parentNode.parentNode
		jumpFunction(liDom,this.parentNode.getAttribute(''))
	}
	function checkBoxTapped(){
		blurAllInput()
		var parentNode = this.parentNode
		var emptyStyleDom = parentNode.parentNode.querySelector('.emptyStyle')
		if (emptyStyleDom) {
			emptyStyleDom.classList.remove('emptyStyle')
		}
		if (parentNode.getAttribute('class').indexOf('dhc-active') != -1) {
			parentNode.classList.remove('dhc-active')
			totalScore -= parseFloat(parentNode.getAttribute('data-score'))
			$('#totalScore')[0].innerHTML = keepTwoDecimalPlaces(totalScore)
			var inputDom = parentNode.querySelector('input')
			if (inputDom) {
				inputDom.setAttribute('disabled','')
			}
		}else{
			parentNode.classList.add('dhc-active')
			totalScore += parseFloat(parentNode.getAttribute('data-score'))
			$('#totalScore')[0].innerHTML = keepTwoDecimalPlaces(totalScore)
			var inputDom = parentNode.querySelector('input')
			if (inputDom) {
				inputDom.removeAttribute('disabled')
			}
		}
		var liDom = parentNode.parentNode
		jumpFunction(liDom)
	}
	
	function gaugeTapped(){
		blurAllInput()
		var parentNode = this.parentNode
		var emptyStyleDom = parentNode.parentNode.querySelector('.emptyStyle')
		if (emptyStyleDom) {
			emptyStyleDom.classList.remove('emptyStyle')
		}
		var actives = parentNode.querySelectorAll('.dhc-active')
		if (actives.length > 0) {
			totalScore -= parseInt(actives[actives.length - 1].getAttribute('data-score'))
		}
		totalScore += parseInt(this.getAttribute('data-score'))
		$('#totalScore')[0].innerHTML = keepTwoDecimalPlaces(totalScore)
		var nurfonts = parentNode.querySelectorAll('.nurfont')
		var index = parseInt(this.getAttribute('data-index'))
		var isSelfActive = this.getAttribute('class').indexOf('dhc-active')
		if (isSelfActive != -1) { 
			for (var i = index+1; i < nurfonts.length;i++) {
				nurfonts[i].classList.remove('dhc-active');
			}
			return
		}
		
		for (var i = 0; i <= index ;i++) {
			nurfonts[i].classList.add('dhc-active');
		}
		var liDom = parentNode.parentNode
		jumpFunction(liDom)
	}
	
	function rangeSlide(){
		blurAllInput()
		var dom = this
		var minValue = parseFloat(dom.min)
		var currValue = parseFloat(dom.value) - minValue
		var maxValue = parseFloat(dom.max) - minValue
		
		var tooltip = dom.nextElementSibling
		tooltip.innerHTML = currValue
		var percent = 100*currValue/maxValue
		if (percent < 5) {
			percent = 0
		}else{
			percent = 'calc('+percent+'% - 15px)'
		}
		tooltip.style.left = percent
		
		var liDom = dom.parentNode.parentNode
		jumpFunction(liDom)
	}
	
	function dateTapped(){
		blurAllInput()
		selectDateTime(this,'date')
	}
	function timeTapped(){
		blurAllInput()
		var btn = this;
		timePicker.show(function(items) {
			var str = ''
			if (items[0].text.length < 2) {
				 str += '0'
			}
			str += items[0].text +':'
			if (items[1].text.length < 2) {
				str += '0'
			}
			str += items[1].text+':'
			if (items[2].text.length < 2) {
				str += '0'
			}
			   str += items[2].text
			btn.innerText = str;
			//return false;//返回 false 可以阻止选择框的关闭
			jumpFunction(btn.parentNode)
		});
	}
	function selectDateTime(btn,type){
		var _self = btn
		if(_self.picker) {
			_self.picker.show(function(rs) {
				_self.innerHTML = rs.text
				var emptyStyleDom = btn.parentNode.querySelector('.emptyStyle')
				if (emptyStyleDom) {
					emptyStyleDom.classList.remove('emptyStyle')
				}
				_self.picker.dispose();
				_self.picker = null;
				jumpFunction(btn.parentNode)
			});
		} else {
			var optionsJson = '{"type":"'+type+'"}';
			var options = JSON.parse(optionsJson);
			_self.picker = new mui.DtPicker(options);
			_self.picker.show(function(rs) {
				_self.innerHTML = rs.text
				var emptyStyleDom = btn.parentNode.querySelector('.emptyStyle')
				if (emptyStyleDom) {
					emptyStyleDom.classList.remove('emptyStyle')
				}
				_self.picker.dispose();
				_self.picker = null;
				jumpFunction(btn.parentNode)
			});
		}
	}
	
	//处理其它题目对此题的关联
	function dealRelations(liDom){
		var related = liDom.getAttribute('related')
		if (!related) {
			return
		}
		var relateArr = related.split('^')
		for (var i = 0; i < relateArr.length;i++) {
			var oneRelated = relateArr[i]
			var relateli = $('#UL li[sort="'+parseInt(oneRelated)+'"]')[0];
			if (!relateli) {
				return
			}
			var relatesubs = ','+oneRelated.split(';')[1]+','
			var activeOps = liDom.querySelectorAll('.dhc-active') //选中的选项
			var has = false
			mui.each(activeOps,function (index,element) {
				var optionId = ','+element.getAttribute('data-id')+',';
				if (relatesubs.indexOf(optionId) != -1) {
					has = true
					return false
				}
			})
			if (has) { //有选中的
				relateli.classList.remove('jumped')
			}else{
				relateli.classList.add('jumped')
			}
		}
	}
	//跳题业务
	function jumpFunction(liDom){
		//return
		var liIndex = parseInt(liDom.id)
		var relationNextIndex = liIndex + 1;
		var liDict = quesData[liIndex]
		var JumpType = liDict['JumpType']
		var related = liDom.getAttribute('related')
		var hasjump = liDom.getAttribute('hasjump')
		if (!hasjump) {
			dealRelations(liDom)
			return
		}
		var anyjump = parseInt(liDom.getAttribute('anyjump'))
		var jumpto = parseInt(liDict['RelatedSort'])
		var liClass = liDom.getAttribute('class')
		var isRadia = (liClass.indexOf('radio') != -1)
		var isCheckBox = (liClass.indexOf('checkBox') != -1)
		var activeOps = liDom.querySelectorAll('.dhc-active') //选中的选项
		var activeCount = activeOps.length
		var nextElement = liDom.nextElementSibling
		var has = false
		if (!anyjump && hasjump) {
			var relatesubs = ','+liDict['RelatedSub']+','//选项
			mui.each(activeOps,function (index,element) {
				var optionId = ','+element.getAttribute('data-id')+',';
				if (relatesubs.indexOf(optionId) != -1) {
					has = true
					return false
				}
			})
		}
		while(nextElement){
			var sort = parseInt(nextElement.getAttribute('sort'))
			if (jumpto &&sort >= jumpto) {
				break
			}
			if (anyjump) { //无条件跳题
				if ((!isRadia && !isCheckBox) ||  activeCount != 0) { //不是单选和多选 或有答案
					nextElement.classList.add('jumped')
					clearJumpedUIAns(nextElement)
					dealRelations(nextElement)
					nextElement = nextElement.nextElementSibling
					return
				}
			}else if (has) {
				nextElement.classList.add('jumped')
				clearJumpedUIAns(nextElement)
				dealRelations(nextElement)
				nextElement = nextElement.nextElementSibling
				continue
			}
			var relation = nextElement.getAttribute('relation') //关联其它题目
			if (relation) {
				var sortLi = $('#UL li[sort="'+parseInt(relation)+'"]')[0];
				var relatesubs = ','+relation.split(';')[1]+','
				var activeOps = sortLi.querySelectorAll('.dhc-active') //选中的选项
				var has2 = false
				mui.each(activeOps,function (index,element) {
					var optionId = ','+element.getAttribute('data-id')+',';
					if (relatesubs.indexOf(optionId) != -1) {
						has2= true
						return false
					}
				})
				if (has2) { //有选中的
					nextElement.classList.remove('jumped')
				}else{
					nextElement.classList.add('jumped')
				}
			}else{
				nextElement.classList.remove('jumped')
			}
			nextElement = nextElement.nextElementSibling
		}
	}
	
	//清空跳题跳过的题目数据
	function clearJumpedUIAns(dom){
		//'radio checkBox SingleBlank multiBlank gauge slide date time'
		var  domClass = dom.getAttribute('class')
		
		if (domClass.indexOf('radio') != -1 || domClass.indexOf('checkBox') != -1) {
			var activeOPs = dom.querySelectorAll('.option.dhc-active')
			mui.each(activeOPs,function (index,element) {
				element.classList.remove('dhc-active')
				var input = element.querySelector('input')
				if (input) {
					input.value = ""
				}
			})
		}else if (domClass.indexOf('SingleBlank') != -1) {
			dom.querySelector('textarea').value = ""
		}else if (domClass.indexOf('multiBlank') != -1) {
			var inputs = dom.querySelectorAll('input')
			mui.each(inputs,function (index,element) {
				element.value = ""
			})
		}else if (domClass.indexOf('gauge') != -1) {
			var nurfonts = dom.querySelectorAll('.nurfont.dhc-active')
			mui.each(nurfonts,function (index,element) {
				element.classList.remove('dhc-active')
			})
		}else if (domClass.indexOf('slide') != -1) {
			var range = dom.querySelector('input[type="range"]')
			range.value = range.min
			var toop = dom.querySelector('.mui-tooltip')
			toop.innerHTML = range.min
			toop.style.left = '0'
		}else if (domClass.indexOf('date') != -1 || domClass.indexOf('time') != -1) {
			dom.querySelector('.nurfont').innerHTML = ""
		}
	}
	function blurAllInput(){
		mui('#UL input[type="text"]').each(function (index,element) {
			element.blur()
		})
		mui('#UL textarea').each(function (index,element) {
			element.blur()
		})
	}
	//单项填空和多项填空录入文字
	function changeEmpty(){
		var value = this.value;
		if (value != '' && this.parentNode.querySelector('.emptyStyle')) {
			var emptyStyleDom = this.parentNode.querySelector('.emptyStyle')
			emptyStyleDom.classList.remove('emptyStyle')
		}
		jumpFunction(this.parentNode)
	}
	
	function updateHeaderUI(){
		var status = sourceData['Status']
		var statusIcon = 'nur-weitianxie'
		if (status == 'N') { //A未保存、N已保存、Y已提交
			statusIcon = 'nur-statusS'
		}else if(status == 'Y'){
			statusIcon = 'nur-statusR';
		}
		$('#statusIcon')[0].classList.add(statusIcon)
		$('#title')[0].innerHTML = sourceData['PerName'] +' 护理调查'
		$('#statTitle')[0].innerHTML = sourceData['SurveyTitle']
		$('#statContent')[0].innerHTML = sourceData['SurveyContent']
		$('#startDate')[0].innerHTML = sourceData['StDate']+ ' — '+sourceData['EndDate']
		$('#statMark')[0].innerHTML = sourceData['Remarks']
		$('#wrapper')[0].style.top = 54 + $('#titleArea')[0].clientHeight + 'px'
	}
	//保持两位小数
	function keepTwoDecimalPlaces(num) {
		var numStr = num + '';
		var dropIndex = numStr.indexOf('.');
		if(dropIndex != -1 && numStr.length > dropIndex + 3) {
			var third = numStr.substr(dropIndex + 3, 1);
			var thirdInt = parseInt(third);
			if(thirdInt < 5) {
				numStr = numStr.substring(0, dropIndex + 3);
				return numStr;
			}
			var intPatr = parseInt(numStr.substring(0, dropIndex));
			var first = parseInt(numStr.substr(dropIndex + 1, 1));
			var secondInt = parseInt(numStr.substr(dropIndex + 2, 1)) + 1;
			if(secondInt > 9) {
				first += 1;
				if(first > 9) {
					numStr = (intPatr + 1);
				} else {
					numStr = intPatr + '.' + first;
				}
			} else {
				numStr = intPatr + '.' + first + secondInt;
			}
		}
		if(isNaN(numStr)) {
			return ''
		}
		return numStr;
	}
	
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui.back=function(){
			plus.nativeUI.closeWaiting()
			plus.webview.currentWebview().close()
		}
		loginInfo = app.getState()
		
		var self = plus.webview.currentWebview()
		sourceData = self.sourceData
		//sourceData['RowId'] = ''
		RowId = sourceData['RowId']
		if (sourceData['Status'] == 'Y') {
			disabledStr = 'disabled'
		}
		updateHeaderUI();
		$('#tipPopo').on('tap','.closeBtn',function(){
			$('#tipPopo').popover('toggle');
		});
		mui('#wrapper').on('tap','li .tip',tipShow)  //提示
		
		if (sourceData['Status'] == 'Y') {
			getStatDetailData();
			return
		}
		$('.submitBtn')[0].style.display = 'none'
		$('.saveBtn')[0].style.display = 'none'
		mui('#wrapper').on('tap','li.radio .circle',radioTapped)  //单选
		mui('#wrapper').on('tap','li.radio .opTitle',radioTapped)  //单选
		mui('#wrapper').on('tap','li.checkBox .square',checkBoxTapped)  //多选
		mui('#wrapper').on('tap','li.checkBox .opTitle',checkBoxTapped)  //多选
		mui('#wrapper').on('input','li.SingleBlank textarea',changeEmpty) //单项填空
		mui('#wrapper').on('input','li.multiBlank input[type="text"]',changeEmpty) //多项填空
		mui('#wrapper').on('tap','li.gauge .option .nurfont',gaugeTapped) //量表
		mui('#wrapper').on('input','li.slide input[type="range"]',rangeSlide) //滑动
		mui('#wrapper').on('tap','li.date .nur-rili',dateTapped) //日期
		mui('#wrapper').on('tap','li.time .nur-shijian',timeTapped) //时间

		timePicker = new $.PopPicker({
			layer: 3,
			noLink: true
		});
		var hourArr = []
		for (var i=0; i < 24;i++) { //时
			hourArr[i] = {'text':''+i,'value':''+i}
		}
		var minArr = [];
		var secArr = [];
		for (var i=0; i < 60;i++) { //分/秒
			minArr[i] = {'text':''+i,'value':''+i}
			secArr[i] = {'text':''+i,'value':''+i}
		}
		timePicker.setData([hourArr,minArr,secArr]);
		$('#wrapper').on('tap','.saveBtn',saveDetailData);
		$('#wrapper').on('tap','.submitBtn',saveDetailData);
		getStatDetailData()
	}
	
})(mui)
/*
	"RowId": "13__1",-----护士填写调查报告id
	"Answer": "",-----备选项
	"QuesDesc": "单选测试",-----标题内容
	"QuesType": "单选",-----题型
	"WriteTips": "",-----填写提示
	"IsRequired": "false",-----是否必填
	"QuesOption": "是」2」」」0「是输入框」1」true」」1",-----选项	以「分割选项，内容」分数」」」顺序
	"JumpType": "",-----跳题类型
			N:无条件跳题,直接跳过 
			X:选项跳题 ---只有单选和多选能选项跳题
			G:题目关联
			N和X是向下跳题,题目关联是向上关联的
	
	
	"ArrangeType": "M",-----
	"IsCount": "",-----IsCount是否计分
	"Rules": "false」不能为空",-----是否必填
	"QuesScore": "2",-----问题分数
	"QuesStatus": "Y",-----状态
	"QuesMin": "",----------滑动条最小值
	"QuesMax": "",-----滑动条最大值
	"QuesMinDesc": "",-----滑动条最小值描述
	"QuesMaxDesc": "",-----滑动条最小值描述
	"InputHeight": "", -----输入框高度
	"InputWidth": "", -----输入框宽度
	"RelatedQues": "", -----关联题目
	"RelatedSub": "", -----关联题目选项id
	"RelatedSort": "", -----关联题目序号 0,1,2,3
	"RelatedSubSort": "", -----关联题目选项--逗号分割 1,2,3,4
	"ShowFlag": "Y", -----ShowFlag
	"Sort": "1" -----序号

跳题逻辑
1.单选 多选 :按选项跳题/无条件跳题/题目关联
2.其它题型 无条件跳题/题目关联
	
题目关联 只能向上关联单选/多选

显示逻辑
1.按照操作顺序来显示: 后操作的优先级更高
	例1 本题目被(无条件或按选项)跳过后 又满足了题目关联条件 则本题会显示
	例2 本题目先满足了题目关联条件显示了 又被(无条件或按选项)跳过 则本题不会显示
	
2.同时满足(无条件或按选项)跳过同时又满足了题目关联条件 则题目关联条件被忽略

3.无条件跳题 被跳过的题目 要清除别的题目对这些题目的关联 这些题目的答案也要清除
*/